package fr.LesLoutresSauvages.laloutresportive.util;

import org.json.*;

public class Sport implements JsonConvertible {
	private int id;
	private String nom;

	public Sport() {
		super();
		this.id = 0;
		this.nom = "";
	}

	public Sport(int id, String nom) {
		super();
		this.id = id;
		this.nom = nom;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getNom() {
		return nom;
	}

	public void setNom(String nom) {
		this.nom = nom;
	}

	@Override
	public String toString() {
		return "Sport [id=" + id + ", nom=" + nom + "]";
	}

	@Override
	public String toJSON() {
		JSONObject jObj = new JSONObject();
		try {
			jObj.put("id", this.getId());
			jObj.put("nom", this.getNom());
		} catch (JSONException e) {
			e.printStackTrace();
		}

		return (jObj.toString());
	}

	@Override
	public void fromJSON(String str) {
		try {
			JSONObject jObj = new JSONObject(str);
			this.setId(jObj.getInt("id"));
			this.setNom(jObj.getString("nom"));
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}
}
